package deepseek;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * https://github.com/ollama/ollama/blob/main/docs/api.md
 */
public class Knowledege {
    /**
     * 向指定 URL 发送 POST 请求并打印响应结果
     * @param args 命令行参数（不使用）
     */
    public static void main(String[] args) {
        String url = "http://localhost:11434/api/knowledge";
        HttpRequest request = HttpUtil.createPost(url);
        Map<String, String> headers = new HashMap<>();
        String authorization = "";//f"Bearer {api_key}"
        headers.put("Authorization", authorization);
        headers.put("Content-Type", "application/json");
        request.addHeaders(headers);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("model","deepseek-r1:8b");
        jsonObject.put("stream",false);
        JSONObject message = new JSONObject();
        message.put("question","什么是人工智能？");
        message.put("answer","人工智能是计算机系统能够执行通常需要人类智能的任务。");
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(message);
        jsonObject.put("messages",jsonArray);
        // 封装参数，对象转json
        String body =JSONObject.toJSONString(jsonObject);
        System.out.println("入参========"+body);
        // 发送请求
        String infoStr = request.body(body).timeout(30000).execute().body();
        System.out.println("出参========"+infoStr);
    }
}
